//
//  RecordCell.m
//  CaiPiao
//
//  Created by l wb on 2018/5/22.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "RecordCell.h"

@implementation RecordCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(void)setWinNumWith:(NSString*)winNumber{
    for (UIView* view in self.winNumBoxView.subviews) {
        [view removeFromSuperview];
    }
    NSArray* checkArray = [winNumber componentsSeparatedByString:@","];
    if ([checkArray count]>13) {
        for (int i=0; i<[checkArray count]; i++) {
            UIView* numberView = [[UIView alloc] initWithFrame:CGRectMake(i*(12+6), 10, 12, 25)];
            numberView.backgroundColor = [UIColor colorWithRed:33/255.0 green:172/255.0 blue:109/255.0 alpha:1];
            numberView.clipsToBounds = YES;
            numberView.layer.cornerRadius = 2;
            
            
            UILabel* numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 12, 25)];
            numberLabel.font = [UIFont boldSystemFontOfSize:15];
            numberLabel.textColor = [UIColor whiteColor];
            numberLabel.textAlignment = NSTextAlignmentCenter;
            numberLabel.text = [checkArray objectAtIndex:i];
            
            [numberView addSubview:numberLabel];
            [self.winNumBoxView addSubview:numberView];
        }
        return;
    }
    NSArray* winNumberArray = [winNumber componentsSeparatedByString:@"+"];
    if ([winNumberArray count]>0) {
        NSArray* redArray;
        NSArray* blueArray;
        
        NSString* redString = [winNumberArray objectAtIndex:0];
        if ([redString rangeOfString:@","].location == NSNotFound) {
            redArray = [redString componentsSeparatedByString:@" "];
        }else{
            redArray = [redString componentsSeparatedByString:@","];
        }
        if ([winNumberArray count]>1) {
            NSString* blueString = [winNumberArray objectAtIndex:1];
            if ([blueString rangeOfString:@","].location == NSNotFound) {
                blueArray = [blueString componentsSeparatedByString:@" "];
            }else{
                blueArray = [blueString componentsSeparatedByString:@","];
            }
        }
        float spacingX = 0;
        for (int i=0; i<[redArray count]; i++) {
            UIView* numberView = [[UIView alloc] initWithFrame:CGRectMake(i*(25+5), 10, 25, 25)];
            numberView.backgroundColor = [UIColor colorWithRed:(255.0/255.0) green:(90/255.0) blue:0 alpha:1];
            UILabel* numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
            numberLabel.font = [UIFont boldSystemFontOfSize:15];
            numberLabel.textColor = [UIColor whiteColor];
            numberLabel.textAlignment = NSTextAlignmentCenter;
            numberLabel.text = [redArray objectAtIndex:i];
            [numberView addSubview:numberLabel];
            numberView.layer.cornerRadius = 25*0.5;
            [self.winNumBoxView addSubview:numberView];
            spacingX+=(25+5);
        }
        
        for (int i=0; i<[blueArray count]; i++) {
            UIView* numberView = [[UIView alloc] initWithFrame:CGRectMake(spacingX, 10, 25, 25)];
            numberView.backgroundColor = [UIColor colorWithRed:(69.0/255.0) green:(160/255.0) blue:(255.0/255.0) alpha:1];
            UILabel* numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
            numberLabel.font = [UIFont boldSystemFontOfSize:15];
            numberLabel.textColor = [UIColor whiteColor];
            numberLabel.textAlignment = NSTextAlignmentCenter;
            numberLabel.text = [blueArray objectAtIndex:i];
            [numberView addSubview:numberLabel];
            numberView.layer.cornerRadius = 25*0.5;
            [self.winNumBoxView addSubview:numberView];
            spacingX+=(25+5);
        }
    }
    
}

@end
